package com.byx.imserverutil.netty;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * NettyChannelContainer
 * 存储所有通道的容器抽象类
 * @author Superb
 * @date 2021/2/20 20:56
 */
public abstract class AbstractChannelContainer<K,V> implements ChannelContainer{

    public final Map<K, V> CHANNELS=new ConcurrentHashMap<K, V>();

    @Override
    public abstract <C> void addChannel(C c);

    @Override
    public abstract <I, C> C removeChannel(I id);

    @Override
    public abstract <I, C> C getChannel(I id);

    //    public NettyChannel removeChannel(Channel channel){
//        if(channel != null){
//            for (Map.Entry<Integer, NettyChannel> entry : CHANNELS.entrySet()) {
//                if(channel.id().toString().equals(entry.getValue().getChannelId())){
//                    return removeChannel(entry.getKey());
//                }
//            }
//        }
//        return null;
//    }
}
